﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Order.Domain.OrderDomain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Order.Interstructrue
{
    public class MedicalDbContext : DbContext
    {
        public MedicalDbContext(DbContextOptions options) : base(options)
        {
        }
        protected MedicalDbContext()
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                // 设计时默认连接字符串
                optionsBuilder.UseMySql("server=10.223.10.42;uid=root;pwd=root;database=order",
                    new MySqlServerVersion(new Version(5, 7)));
            }
        }

        /// <summary>
        /// 药品实体（处方明细）
        /// </summary>
        public DbSet<Drug> Drug { get; set; }

        /// <summary>
        /// 药品订单
        /// </summary>
        public DbSet<DrugOrders> DrugOrders { get; set; }

        /// <summary>
        /// 问诊详情
        /// </summary>
        public DbSet<Interrogation> Interrogation { get; set; }

        /// <summary>
        /// 问诊订单
        /// </summary>
        public DbSet<InterrogationOrder> InterrogationOrder { get; set; }

        /// <summary>
        /// 患者信息
        /// </summary>
        public DbSet<Patient> Patient { get; set; }

        /// <summary>
        /// 处方信息
        /// </summary>
        public DbSet<Prescription> Prescription { get; set; }

        /// <summary>
        /// 处方订单
        /// </summary>
        public DbSet<PrescriptionOrder> PrescriptionOrder { get; set; }

        /// <summary>
        /// 退款信息
        /// </summary>
        public DbSet<Refund> Refund { get; set; }

        /// <summary>
        /// 挂号信息
        /// </summary>
        public DbSet<Registration> Registration { get; set; }

        /// <summary>
        /// 挂号订单
        /// </summary>
        public DbSet<RegistrationOrder> RegistrationOrder { get; set; }
    }

    /// <summary>
    /// 设计时工厂，用于EF Core迁移
    /// </summary>
    public class MedicalDbContextFactory : IDesignTimeDbContextFactory<MedicalDbContext>
    {
        public MedicalDbContext CreateDbContext(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder<MedicalDbContext>();
            optionsBuilder.UseMySql("server=10.223.10.42;uid=root;pwd=root;database=order",
                new MySqlServerVersion(new Version(5, 7)));

            return new MedicalDbContext(optionsBuilder.Options);
        }
    }
}
